package com.lt.bcra.controller.questionnaire;


import com.lt.bcra.entity.BcraPersonalFactors;
import com.lt.bcra.exception.BaseException;
import com.lt.bcra.service.BcraPersonalFactorsService;
import com.lt.bcra.result.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 个人因素表 前端控制器
 * </p>
 *
 * @author LuoTian
 * @since 2022-05-25
 */
@Api(tags = "1.个人因素表")
@CrossOrigin //跨域可以前端配置
@RestController
@RequestMapping("bcra/personalFactors")
public class BcraPersonalFactorsController {

    private static Logger log = LoggerFactory.getLogger(BcraPersonalFactorsController.class);

    @Autowired
    private BcraPersonalFactorsService bcraPersonalFactorsService;


    @PostMapping("/creatPersonalFactors")
    @ApiOperation("填写个人因素")
    @ApiParam(value = "bcraPersonalFactors")
    public ResultData creatNew(@RequestBody BcraPersonalFactors bcraPersonalFactors) throws BaseException {
        if (log.isDebugEnabled()) log.debug("创建个人因素表 BcraPersonalFactorsController");

        return bcraPersonalFactorsService.saveModule(bcraPersonalFactors);
    }

    @PostMapping("/updatePersonalFactors")
    @ApiOperation("修改个人因素")
    @ApiParam(value = "bcraPersonalFactors")
    public ResultData update(@RequestBody BcraPersonalFactors bcraPersonalFactors) throws BaseException {
        if (log.isDebugEnabled()) log.debug("修改个人因素表 BcraPersonalFactorsController");

        return bcraPersonalFactorsService.updateModule(bcraPersonalFactors);
    }

    @DeleteMapping("/deletePersonalFactors")
    @ApiOperation("删除个人因素")
    @ApiParam(value = "问卷编号")
    public ResultData delete(String questionnaireCode) throws BaseException{
        if (log.isDebugEnabled()) log.debug("删除个人因素表 BcraPersonalFactorsController");

        return bcraPersonalFactorsService.removeByQuesCode(questionnaireCode);
    }

    @GetMapping("/getPersonalFactors")
    @ApiOperation("查看个人因素")
    @ApiParam(value = "问卷编号")
    public ResultData list(String questionnaireCode) throws BaseException{
        if (log.isDebugEnabled()) log.debug("删除个人因素表 BcraPersonalFactorsController");

        return bcraPersonalFactorsService.selectByQuesCode(questionnaireCode);
    }
}

